﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.MountAndBlade.View.MissionViews.Singleplayer.MissionCustomBattlePreloadView
// Assembly: TaleWorlds.MountAndBlade.View, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 61152EB8-513B-4D4A-8AC0-0D1465C6CF6C
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\Modules\Native\bin\Win64_Shipping_Client\TaleWorlds.MountAndBlade.View.dll

using System.Collections.Generic;
using TaleWorlds.Core;

#nullable disable
namespace TaleWorlds.MountAndBlade.View.MissionViews.Singleplayer
{
  public class MissionCustomBattlePreloadView : MissionView
  {
    private PreloadHelper _helperInstance = new PreloadHelper();
    private bool _preloadDone;

    public override void OnPreMissionTick(float dt)
    {
      if (this._preloadDone)
        return;
      MissionCombatantsLogic missionBehavior1 = this.Mission.GetMissionBehavior<MissionCombatantsLogic>();
      List<BasicCharacterObject> characters = new List<BasicCharacterObject>();
      foreach (IBattleCombatant allCombatant in missionBehavior1.GetAllCombatants())
        characters.AddRange(((CustomBattleCombatant) allCombatant).Characters);
      this._helperInstance.PreloadCharacters(characters);
      SiegeDeploymentMissionController missionBehavior2 = Mission.Current.GetMissionBehavior<SiegeDeploymentMissionController>();
      if (missionBehavior2 != null)
        this._helperInstance.PreloadItems(missionBehavior2.GetSiegeMissiles());
      this._preloadDone = true;
    }

    public override void OnSceneRenderingStarted()
    {
      this._helperInstance.WaitForMeshesToBeLoaded();
    }

    public override void OnMissionStateDeactivated()
    {
      base.OnMissionStateDeactivated();
      this._helperInstance.Clear();
    }
  }
}
